package com.magic.babyphotos;

import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.magic.babyphotos.R;
import com.magic.babyphotos.util.AudioPlayer;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

public class EntryActivity extends BaseActivity implements OnTouchListener, OnClickListener
{
	String tag = "EntryActivity";
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.entry_layout);
        ImageButton newSnapButton = (ImageButton)this.findViewById(R.id.newsnap);
        newSnapButton.setOnTouchListener(this);
        newSnapButton.setOnClickListener(this);
        ImageButton helpButton = (ImageButton)this.findViewById(R.id.help);
        helpButton.setOnTouchListener(this);
        helpButton.setOnClickListener(this);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        AudioPlayer.getInstance().setLoop(true);
        
        AdView adView = (AdView)this.findViewById(R.id.adView);
        if(adView != null)
        {
            adView.loadAd(new AdRequest());
        }
    }
    
    protected void onPause() {
        super.onPause();
        AudioPlayer.getInstance().stop();
    }
    
    protected void onResume()
    {
    	super.onResume();
    	AudioPlayer.getInstance().play(R.raw.title);
    }
    
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.newsnap)
		{
			if(event.getAction() == MotionEvent.ACTION_DOWN)
			{
				Drawable bg = this.getResources().getDrawable(R.drawable.bt_newsnap);
				bg.setAlpha(200);
				v.setBackgroundDrawable(bg);
			}
			else if(event.getAction() == MotionEvent.ACTION_UP)
			{
				Drawable bg = this.getResources().getDrawable(R.drawable.bt_newsnap);
				bg.setAlpha(255);
				v.setBackgroundDrawable(bg);
			}
		}
		else if(v.getId() == R.id.help)
		{
		    if(event.getAction() == MotionEvent.ACTION_DOWN)
            {
                Drawable bg = this.getResources().getDrawable(R.drawable.bt_help);
                bg.setAlpha(200);
                v.setBackgroundDrawable(bg);
            }
            else if(event.getAction() == MotionEvent.ACTION_UP)
            {
                Drawable bg = this.getResources().getDrawable(R.drawable.bt_help);
                bg.setAlpha(255);
                v.setBackgroundDrawable(bg);
            }
		}
		return false;
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId())
		{
			case  R.id.newsnap:
			{
				this.startActivity(new Intent(this, ChoosePhotoActivity.class));
				break;
			}
			case R.id.help:
			{
			    this.startActivity(new Intent(this, HelpActivity.class));
                break;
			}
		}
	}
}
